package com.hyf.test;

import com.hyf.bytecode.Gem;
import org.junit.Test;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author baB_hyf
 * @date 2021/05/04
 */
public class T {

    @Test
    public void testA() {

        String[] strs = {"account", "asdf", "class", "generator_user", "hello", "logic_user", "mapper_user",
                "mp_class", "mp_user", "orders", "person", "spring_tx_test_money", "student", "t_red_packet",
                "t_user", "t_user_red_packet", "teacher", "teacher_ann", "test_generate", "user", "user_ann",
                "user_max", "users"};

        // Gem.cacheAllTableList = Arrays.asList(strs);

        // String[] tables = {"t_*", "*_user", "class", "t*ch*", "p*r*s*n", "ac*nt"};
        // String[] tables = {"****************t******ch***********"};
        // String[] tables = {"er_m*****"};
        String[] tables = {"*"};
        List<String> stringList = Arrays.asList(tables);

        // List<String> generateTableList = Gem.getGenerateTableList(stringList);
        // System.out.println(generateTableList);

    }

    @Test
    public void testB() {
        String s = "111";
        System.out.println(s.indexOf(""));
    }

    @Test
    public void testC() {
        String s = "***1***2***";
        String[] split = s.split("\\*");
        List<String> stringList = Arrays.asList(split);
        String[] strings = stringList.toArray(new String[0]);
        System.out.println(Arrays.asList(split));
        System.out.println(stringList);
        stringList = new ArrayList<>(stringList);
        stringList.removeIf(String::isEmpty);
        System.out.println(stringList);
        String[] strings2 = stringList.toArray(new String[0]);
        System.out.println(Arrays.asList(strings));
        System.out.println(Arrays.asList(strings2));


        String s2 = "*";
        String[] split1 = s2.split("\\*");
        System.out.println(Arrays.asList(split1));
    }

    @Test
    public void testD() {
        String t_user2 = Gem.getIdColumnName("account");
        System.out.println(t_user2);
    }

    @Test
    public void testE() {
        String s = "***";

        String replace = s.replace("*", "1");
        System.out.println(replace);
    }

    @Test
    public void testF() {
        Map<String, String> orderTreeMap = new TreeMap<>((o1, o2) -> {
            String r1 = o1.replace(" ", "").replace("*", "");
            String r2 = o2.replace(" ", "").replace("*", "");
            return r2.length() - r1.length();
        });

        orderTreeMap.put("11", "111");
        orderTreeMap.put("222", "111");
        System.out.println(orderTreeMap);
    }

    @Test
    public void testG() {
        List<String> entityMetaList = new ArrayList<>();
        entityMetaList.add("1");
        entityMetaList.add("2");
        entityMetaList.add("3");
        entityMetaList.add("4");


        Map<String, String> orderTreeMap = new TreeMap<>((o1, o2) -> {
            String r1 = o1.replace(" ", "").replace("*", "");
            String r2 = o2.replace(" ", "").replace("*", "");
            int i = r2.length() - r1.length();
            return i == 0 ? r1.compareTo(r2) : i;
        });

        Map<String, String> tableNameMap2 = entityMetaList.stream().collect(
                Collectors.toMap(String::toString, mata -> mata, (meta1, meta2) -> {
                    System.out.println(meta1);
                    System.out.println(meta2);
                    throw new RuntimeException("ddd");
                }, HashMap::new));
        System.out.println(tableNameMap2);

        Map<String, String> tableNameMap = entityMetaList.stream().collect(
                Collectors.toMap(String::toString, mata -> mata, (meta1, meta2) -> {
                    System.out.println(meta1.equals(meta2));
                    System.out.println(meta1.hashCode());
                    System.out.println(meta2.hashCode());
                    System.out.println(meta1);
                    System.out.println(meta2);
                    throw new RuntimeException("ddd");
                }, () -> orderTreeMap));
        System.out.println(tableNameMap);
    }
}
